/* 
 *   Copyright (c) 2021 Liu Bingyi
 *   MineSweeping is licensed under Mulan PSL v2.
 *   You can use this software according to the terms and conditions of the Mulan PSL v2.
 *   You may obtain a copy of Mulan PSL v2 at:
 *            http://license.coscl.org.cn/MulanPSL2
 *   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 *   EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 *   MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 *   See the Mulan PSL v2 for more details.
 * 
 *   Author: LiuBingyi
 *   Email: cecillearofa@163.com
 *   Created at 2021/03/24 22:12:59
 */

package minesweeping;

import java.util.Scanner;

public class MineSweeping {

    public static void main(String[] args) {
        MineSweepingBoard ms = new MineSweepingBoard(9, 9, 10);
        MineSweepingDisplay d = new MineSweepingDisplay(ms);

        String gameArg;

        Scanner s = new Scanner(System.in);

        while (d.isGameOver()) {
            d.flushmistMap();
            d.printMap();

            if (s.hasNextLine()) {
                gameArg = s.nextLine();
                String[] gameArgs = gameArg.split(" ");
                if (gameArgs.length == 2) {
                    d.click(Integer.parseInt(gameArgs[0]), Integer.parseInt(gameArgs[1]));
                } else if (gameArgs.length == 3) {
                    d.click(recorder(gameArgs[0]), Integer.parseInt(gameArgs[1]), Integer.parseInt(gameArgs[2]));
                }
            }

        }
        s.close();
        d.flushLightMap();
        d.printMap();
    }

    private static byte recorder(String arg) {
        if (Character.isDigit(arg.charAt(0))) {
            return Byte.parseByte(arg);
        }
        if (arg.equals("c")) {
            return MineSweepingDisplay.DISPLAY_ORDER_OPEN;
        }
        if (arg.equals("m")) {
            return MineSweepingDisplay.DISPLAY_ORDER_MARK;
        } else
            return -1;
    }
}
